$(function () {
    //轮播图
    swiper();
    //  填充页面信息
    index();

})

// 填充页面
function index() {
// 请求后台
    $.ajax({
        url : "/init/contact/webs/selectContact",
        data : CommonUtils.encapsulationData({}),
        type : 'post',
        dataType : 'json',
        async:false,
        contentType : "application/json",
        success : function(data) {
            if (data) {
                var serverPath = CommonUtils.getServerRoot();
                // 公司信息
                var contact = data.contact;

                //导航栏 电话
                var hotline = '<a title="免费咨询热线"><span>'+contact.contactPhone+'</span></a><u></u>';
                $("#hotline").append(hotline);
                //导航栏 电话
                var phone = '<a href="tel:'+contact.contactPhone+'" title="点击直拨热线"><span class="glyphicon glyphicon-earphone"></span></a><span class="glyphicon glyphicon-th-large"></span>';
                $("#tel-phone").append(phone);

                // Logo图标
                var logo = '<img src="'+serverPath + contact.logoImg+'" alt="我的网站" class="img-responsive" />';
                $("#logo").append(logo);

                // 填充产品
                var product = data.product;
                var productHtml = "";
                for (var i = 0; i < product.length; i++) {
                    var products = product[i];
                    //图片地址拼接
                    var imgURL = products.productImgUrl;
                    var imgPath = serverPath+imgURL;
                    //把图片路径中\该为/
                    var re = new RegExp("\\\\","g");
                    imgPath = imgPath.replace(re, "/");
                    productHtml += '<div class="swiper-slide">\n' +
                        '               <a href="product/product_detail.html?productId='+CommonUtils.compile(products.productId)+'" target="_blank">\n' +
                        '                                <img src="'+imgPath+'" alt="'+ products.productTitleOne +'" />\n' +
                        '                                <p><strong>'+ products.productTitleOne +'</strong><br />'+ products.productTitleTwo +'</p></a>\n' +
                        '                        </div>';
                }
                $("#product").append(productHtml);

                //填充客户信息
                var customer = data.customer;
                var customerHtml = "";
                for (var i = 0; i < customer.length; i++) {
                    var customers = customer[i];
                    //图片地址拼接
                    var imgURL = customers.customerLogoUrl;
                    var imgPath = serverPath+imgURL;
                    var re = new RegExp("\\\\","g");
                    imgPath = imgPath.replace(re, "/");
                    console.log("customer imgPath:" + imgPath)
                    customerHtml += '<li class="customer" title="'+customers.customerName+'" onclick="openUrl(\''+customers.customerWebUrl+'\')" ' +
                        'style=\'background: url('+imgPath+');background-size:230px 150px;\'><span>'+customers.customerName+'</span></li>';
                }
                $("#customer").append(customerHtml);

                // 关于 中的思想以及简介
                var thought = " <p>"+ contact.companyThought+"</p>";
                $("#thought").append(thought);
                var about = " <p>"+ contact.companyAbout+"</p>";
                $("#about").append(about);

                // 关于 中的荣誉
                var honor = data.honor;
                var honorHtml = "";
                for (var i = 0; i < honor.length; i++) {
                    var honors = honor[i];
                    honorHtml += '<li>'+honors.honorYear+'<u>-</u>'+honors.honorEvent+'</li>';
                }
                $("#honor").append(honorHtml);

                // 关于 中的事件
                var event = data.event;
                var eventHtml = "";
                for (var i = 0; i < event.length; i++) {
                    var events = event[i];
                    eventHtml += '<td><u>'+events.eventNum+'</u>'+events.eventContent+'</td>';
                }
                $("#event").append(eventHtml);

                // 联系页面左边信息
                var contantLeft = '<p>tel：'+contact.contactPhone+'</p>\n' +
                    '                        <p>'+contact.companyName+'</p>\n' +
                    '                        <p>'+contact.companyAddress+'</p>';
                $("#contactLeft").append(contantLeft);
                // 联系页面右边信息
                var contactRight = 'Email：'+contact.contactQQ+'@qq.com<br />\n' +
                    '                        Copyright 2019<u></u>\n' +
                    '                        '+contact.companyName+' 版权所有<br />\n' +
                    '                        粤ICP备19126112号<br />' +
                    '店铺链接：<a style="color: red" href="'+contact.extendField1+'" target="view_window">'+contact.companyName+'</a>';
                $("#contactRight").append(contactRight);

                //联系页面 微信二维码
                var contantWechat = '<img style="width: 150px;height: 150px;" src="'+serverPath + contact.contactImg+'" alt="扫描关注微信公众账号" />';
                $("#contantWechat").append(contantWechat);

                //侧边qq
                var columnQQ = '<i></i><p>qq咨询<br />qq在线沟通：<br />'+contact.contactQQ+'<br/></p>';
                $("#columnQQ").append(columnQQ);
                // 侧边电话
                var columnTel = '<i></i><p>咨询热线<br />拨打电话沟通：<br />'+contact.contactPhone+'<br /></p>';
                $("#columnTel").append(columnTel);
                //侧边 微信图片
                var columnWechat = '<img src="'+serverPath + contact.contactImg+'" alt="扫描关注微信公众账号" />';
                $("#columnWechat").append(columnWechat);

            }
        }
    });
}

// 新页面打开链接
function openUrl(url) {
    if(null != url && "" != url){
        window.open(url);
    }
}

/**
 * 生成轮播图
 */
function swiper() {
    // 请求后台
    $.ajax({
        url : "/init/swiper/webs/findSwiperLists",
        data : CommonUtils.encapsulationData({}),
        type : 'post',
        dataType : 'json',
        async:false,
        contentType : "application/json",
        success : function(data) {
            if (data) {
                var html = "";
                for (var i=0;i<data.length;i++){
                    //获取图片路径
                    var serverPath = CommonUtils.getServerRoot();
                    var imgURL = data[i].swiperUrl;
                    var imgPath = serverPath+imgURL;
                    //把图片路径中\该为/
                    var re = new RegExp("\\\\","g");
                    var imgPath = imgPath.replace(re, "/");

                    if (i==0) {
                        html += '<div class="swiper-slide nth1" onclick="openUrl(\'product/product_detail.html?productId='+CommonUtils.compile(data[i].productId)+'\')" ' +
                            'style="background-image:url('+imgPath+')!important;">\n' +
                            '                        <div class="box">\n' +
                            '                            <div class="left"></div>\n' +
                            '                            <div class="right">\n' +
                            '                                <span>'+data[i].swiperTitle+'</span>\n' +
                            '                                <p>'+data[i].swiperContent+'</p>\n' +
                            '                            </div>\n' +
                            '                        </div>\n' +
                            '                    </div>';
                    } else if (i==1) {
                        html += '<div class="swiper-slide nth2" onclick="openUrl(\'product/product_detail.html?productId='+CommonUtils.compile(data[i].productId)+'\')" ' +
                            'style="background-image:url('+imgPath+')!important;">\n' +
                            '                        <div class="box">\n' +
                            '                            <span>'+data[i].swiperTitle+'</span>\n' +
                            '                            <p>'+data[i].swiperContent+'</p>\n' +
                            '                        </div>\n' +
                            '                    </div>';
                    } else if (i==2) {
                        html += '<div class="swiper-slide nth3" onclick="openUrl(\'product/product_detail.html?productId='+CommonUtils.compile(data[i].productId)+'\')" ' +
                            'style="background-image:url('+imgPath+')!important;">\n' +
                            '                        <div class="box">\n' +
                            '                            <div class="top">'+data[i].swiperTitle+'</div>\n' +
                            '                            <div class="bottom">'+data[i].swiperContent+'</div>\n' +
                            '                        </div>\n' +
                            '                    </div>';
                    }else if (i==3) {
                        html += '<div class="swiper-slide nth4" onclick="openUrl(\'product/product_detail.html?productId='+CommonUtils.compile(data[i].productId)+'\')" ' +
                            'style="background-image:url('+imgPath+')!important;">\n' +
                            '                        <div class="box">\n' +
                            '                            <div class="top"><span>'+data[i].swiperTitle+'</span></div>\n' +
                            '                            <div class="bottom">'+data[i].swiperContent+'</div>\n' +
                            '                        </div>\n' +
                            '                    </div>';
                    }
                }
                $("#video-swiper").append(html);
            }
        }
    });
}